package 几数之和.两数之和和四数相加;

import java.util.HashMap;

/**
 * @author zhengTao
 * @version 1.0
 * @description: 两数之和
 * @date 2022/10/16 10:59
 */
public class Demo01 {
    public int[] twoSum(int[] nums, int target) {
        HashMap<Integer,Integer> hashMap=new HashMap();
        for (int i = 0; i < nums.length; i++) {
            if(hashMap.containsKey(target-nums[i])){
                return new int[]{hashMap.get(target-nums[i]),i};
            }else {
                hashMap.put(nums[i],i );
            }
        }
        return new int[]{-1,-1};
    }
}
